/* JAI-Ext - OpenSource Java Advanced Image Extensions Library
*    http://www.geo-solutions.it/
*    Copyright 2014 GeoSolutions


* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at

* http://www.apache.org/licenses/LICENSE-2.0

* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.eclipse.imagen.media.scale;

import static org.junit.Assert.*;

import java.awt.*;
import org.eclipse.imagen.Interpolation;
import org.junit.Test;

/**
 * This test-class extends the TestScale class and is used for testing the bicubic interpolation inside the Scale
 * operation. The first method tests the scale operation without the presence of a ROI or a No Data Range. The 2nd
 * method introduces a ROI object calculated using a ROI RasterAccessor while the 3rd method uses an Iterator on the ROI
 * Object. The 4th method performs the scale operation with all the components. The last method is similar to the 4th
 * method but executes its operations on binary images.
 */
public class BicubicScaleTest extends TestScale {
    @Test
    public void testImageScaling() {
        boolean roiPresent = false;
        boolean noDataRangeUsed = false;
        boolean isBinary = false;
        boolean bicubic2DIsabled = true;
        boolean useROIAccessor = false;

        testGlobal(
                useROIAccessor,
                isBinary,
                bicubic2DIsabled,
                noDataRangeUsed,
                roiPresent,
                InterpolationType.BICUBIC_INTERP,
                TestSelection.NO_ROI_ONLY_DATA,
                ScaleType.MAGNIFY);

        testGlobal(
                useROIAccessor,
                isBinary,
                bicubic2DIsabled,
                noDataRangeUsed,
                roiPresent,
                InterpolationType.BICUBIC_INTERP,
                TestSelection.NO_ROI_ONLY_DATA,
                ScaleType.REDUCTION);
    }

    @Test
    public void testImageScalingROIAccessor() {

        boolean roiPresent = true;
        boolean noDataRangeUsed = false;
        boolean isBinary = false;
        boolean bicubic2DIsabled = true;
        boolean useROIAccessor = true;

        testGlobal(
                useROIAccessor,
                isBinary,
                bicubic2DIsabled,
                noDataRangeUsed,
                roiPresent,
                InterpolationType.BICUBIC_INTERP,
                TestSelection.ROI_ACCESSOR_ONLY_DATA,
                ScaleType.MAGNIFY);

        testGlobal(
                useROIAccessor,
                isBinary,
                bicubic2DIsabled,
                noDataRangeUsed,
                roiPresent,
                InterpolationType.BICUBIC_INTERP,
                TestSelection.ROI_ACCESSOR_ONLY_DATA,
                ScaleType.REDUCTION);
    }

    @Test
    public void testImageScalingROIBounds() {

        boolean roiPresent = true;
        boolean noDataRangeUsed = false;
        boolean isBinary = false;
        boolean bicubic2DIsabled = true;
        boolean useROIAccessor = false;

        testGlobal(
                useROIAccessor,
                isBinary,
                bicubic2DIsabled,
                noDataRangeUsed,
                roiPresent,
                InterpolationType.BICUBIC_INTERP,
                TestSelection.ROI_ONLY_DATA,
                ScaleType.MAGNIFY);

        testGlobal(
                useROIAccessor,
                isBinary,
                bicubic2DIsabled,
                noDataRangeUsed,
                roiPresent,
                InterpolationType.BICUBIC_INTERP,
                TestSelection.ROI_ONLY_DATA,
                ScaleType.REDUCTION);
    }

    @Test
    public void testImageScalingTotal() {

        boolean roiPresent = true;
        boolean noDataRangeUsed = true;
        boolean isBinary = false;
        boolean bicubic2DIsabled = true;
        boolean useROIAccessor = true;

        testGlobal(
                useROIAccessor,
                isBinary,
                bicubic2DIsabled,
                noDataRangeUsed,
                roiPresent,
                InterpolationType.BICUBIC_INTERP,
                TestSelection.ROI_ACCESSOR_NO_DATA,
                ScaleType.MAGNIFY);

        testGlobal(
                useROIAccessor,
                isBinary,
                bicubic2DIsabled,
                noDataRangeUsed,
                roiPresent,
                InterpolationType.BICUBIC_INTERP,
                TestSelection.ROI_ACCESSOR_NO_DATA,
                ScaleType.REDUCTION);
    }

    @Test
    public void testImageScalingBinary() {
        boolean roiPresent = true;
        boolean noDataRangeUsed = true;
        boolean isBinary = true;
        boolean bicubic2DIsabled = true;
        boolean useROIAccessor = true;

        testGlobal(
                useROIAccessor,
                isBinary,
                bicubic2DIsabled,
                noDataRangeUsed,
                roiPresent,
                InterpolationType.BICUBIC_INTERP,
                TestSelection.BINARY_ROI_ACCESSOR_NO_DATA,
                ScaleType.MAGNIFY);

        testGlobal(
                useROIAccessor,
                isBinary,
                bicubic2DIsabled,
                noDataRangeUsed,
                roiPresent,
                InterpolationType.BICUBIC_INTERP,
                TestSelection.BINARY_ROI_ACCESSOR_NO_DATA,
                ScaleType.REDUCTION);
    }

    @Test
    public void testInterpolationNoDataBleedByte() {
        assertNoDataBleedByte(Interpolation.getInstance(Interpolation.INTERP_BICUBIC));
    }

    @Test
    public void testInterpolationNoDataBleedShort() {
        assertNoDataBleedShort(Interpolation.getInstance(Interpolation.INTERP_BICUBIC));
    }

    @Test
    public void testInterpolationNoDataBleedFloat() {
        assertNoDataBleedFloat(Interpolation.getInstance(Interpolation.INTERP_BICUBIC));
    }

    @Test
    public void testInterpolationNoDataBleedDouble() {
        assertNoDataBleedDouble(Interpolation.getInstance(Interpolation.INTERP_BICUBIC));
    }

    @Test
    public void testInterpolateInHole() {
        assertInterpolateInHole(Interpolation.getInstance(Interpolation.INTERP_BICUBIC));
    }

    @Test
    public void testPackedImage() {
        super.testPackedImage(InterpolationType.BICUBIC_INTERP);
    }

    @Test
    public void testNoDataOutput() {
        super.testNoDataOutput(InterpolationType.BICUBIC_INTERP);
    }

    @Test
    public void testROILayout() {
        testROILayout(Interpolation.INTERP_BICUBIC);
    }
}
